package com.itheima.thread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class Demo03 {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        FutureTask<Integer> task = new FutureTask<>(new MyCallable());
        Thread t1 = new Thread(task);
        t1.start();
        for (int j = 0; j < 100; j++) {

            System.out.println("main中执行到了"+j);
        }
        Integer i = task.get();

        System.out.println(i);


    }
}


class MyCallable implements Callable<Integer>{
    @Override//这家伙有返回值
    public Integer call() throws Exception {
        String name = Thread.currentThread().getName();
        for (int i = 0; i < 100; i++) {
            System.out.println(name+"中执行到了"+i);
        }
        return 520;
    }
}
